<?php

/**
 * disciplinas actions.
 *
 * @package    GC
 * @subpackage disciplinas
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class disciplinasActions extends sfActions {

    public function executeIndex(sfWebRequest $request) {
        $this->gc_disciplinas = Doctrine_Core::getTable('GcDisciplina')
                ->createQuery('a')
                ->execute();
    }

    public function executeNew(sfWebRequest $request) {
        $this->form = new GcDisciplinaForm();
    }

    public function executeCreate(sfWebRequest $request) {
        $this->forward404Unless($request->isMethod(sfRequest::POST));

        $this->form = new GcDisciplinaForm();

        $this->processForm($request, $this->form);

        $this->setTemplate('new');
    }

    public function executeEdit(sfWebRequest $request) {
        $gc_disciplina = $this->getRoute()->getObject();
        $this->form = new GcDisciplinaForm($gc_disciplina);
    }

    public function executeUpdate(sfWebRequest $request) {
        $gc_disciplina = $this->getRoute()->getObject();
        $this->form = new GcDisciplinaForm($gc_disciplina);

        $this->processForm($request, $this->form);

        $this->setTemplate('edit');
    }

    public function executeDelete(sfWebRequest $request) {
        $request->checkCSRFProtection();
        $gc_disciplina = $this->getRoute()->getObject();
        $gc_disciplina->delete();

        $this->redirect('disciplinas');
    }

    protected function processForm(sfWebRequest $request, sfForm $form) {
        $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
        if ($form->isValid()) {
            $gc_disciplina = $form->save();

            $this->redirect('disciplinas');
        }
    }

}
